home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Complete Linux
/
Complete Linux.iso
/
xwindows
/
demos
/
xfract_1.z
/
xfract_1
/
xfractint-1.06
/
unix.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-28
|
7KB
|
397 lines
/* Unix.c
* This file contains compatibility routines.
*
* This file Copyright 1991 Ken Shirriff. It may be used according to the
* fractint license conditions, blah blah blah.
*/
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <ctype.h>
#include "port.h"
int iocount;
/*
*----------------------------------------------------------------------
*
* clock_ticks --
*
* Return time in CLK_TCK ticks.
*
* Results:
* Time.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
long
clock_ticks()
{
struct timeval tim;
gettimeofday(&tim,NULL);
return tim.tv_sec*CLK_TCK + tim.tv_usec*CLK_TCK/1000000;
}
/* stub */
intdos() {}
/*
*----------------------------------------------------------------------
*
* kbhit --
*
* Get a key.
*
* Results:
* 1 if key, 0 otherwise.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
kbhit()
{
return 0;
}
/*
*----------------------------------------------------------------------
*
* stackavail --
*
* Returns amout of stack available.
*
* Results:
* Available stack.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
long
stackavail()
{
return 8192;
}
#ifndef HAVESTRI
/*
*----------------------------------------------------------------------
*
* stricmp --
*
* Compare strings, ignoring case.
*
* Results:
* -1,0,1.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
stricmp(s1, s2)
register char *s1, *s2; /* Strings to compare. */
{
int c1, c2;
while (1) {
c1 = *s1++;
c2 = *s2++;
if (isupper(c1)) c1 = tolower(c1);
if (isupper(c2)) c2 = tolower(c2);
if (c1 != c2) {
return c1 - c2;
}
if (c1 == 0) {
return 0;
}
}
}
/*
*----------------------------------------------------------------------
*
* strnicmp --
*
* Compare strings, ignoring case. Maximum length is specified.
*
* Results:
* -1,0,1.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
strnicmp(s1, s2, numChars)
register char *s1, *s2; /* Strings to compare. */
register int numChars; /* Max number of chars to compare. */
{
register char c1, c2;
for ( ; numChars > 0; --numChars) {
c1 = *s1++;
c2 = *s2++;
if (isupper(c1)) c1 = tolower(c1);
if (isupper(c2)) c2 = tolower(c2);
if (c1 != c2) {
return c1 - c2;
}
if (c1 == '\0') {
return 0;
}
}
return 0;
}
#endif
/*
*----------------------------------------------------------------------
*
* strlwr --
*
* Convert string to lower case.
*
* Results:
* The string.
*
* Side effects:
* Modifies the string.
*
*----------------------------------------------------------------------
*/
char *
strlwr(s)
char *s;
{
register char *sptr=s;
while (*sptr != '\0') {
if (isupper(*sptr)) {
*sptr = tolower(*sptr);
}
sptr++;
}
return s;
}
/*
*----------------------------------------------------------------------
*
* strupr --
*
* Convert string to upper case.
*
* Results:
* The string.
*
* Side effects:
* Modifies the string.
*
*----------------------------------------------------------------------
*/
char *
strupr(s)
char *s;
{
register char *sptr=s;
while (*sptr != '\0') {
if (islower(*sptr)) {
*sptr = toupper(*sptr);
}
sptr++;
}
return s;
}
/*
*----------------------------------------------------------------------
*
* memicmp --
*
* Compare memory (like memcmp), but ignoring case.
*
* Results:
* -1,0,1.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
memicmp(s1, s2, n)
register char *s1, *s2;
register n;
{
register char c1,c2;
while (--n >= 0)
c1 = *s1++;
if (isupper(c1)) c1 = tolower(c1);
c2 = *s2++;
if (isupper(c2)) c2 = tolower(c2);
if (c1 != c2)
return (c1 - c2);
return (0);
}
/*
*----------------------------------------------------------------------
*
* findpath --
*
* Find where a file is.
* We return filename if it is an absolute path.
* Otherwise we return SRCDIR/filename.
*
* Results:
* Returns full pathname in fullpathname.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
findpath(filename, fullpathname)
char *filename, *fullpathname;
{
if (filename[0]=='/') {
strcpy(fullpathname,filename);
return;
}
strcpy(fullpathname,SRCDIR);
strcat(fullpathname,"/");
strcat(fullpathname,filename);
}
/*
*----------------------------------------------------------------------
*
* filelength --
*
* Find length of a file.
*
* Results:
* Length.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int filelength(fd)
int fd;
{
struct stat buf;
fstat(fd,&buf);
return buf.st_size;
}
/*
*----------------------------------------------------------------------
*
* splitpath --
*
* This is the splitpath code from prompts.c
*
* Results:
* Returns drive, dir, base, and extension.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
splitpath(char *template,char *drive,char *dir,char *fname,char *ext)
{
int length;
int len;
int offset;
char *tmp;
if(drive)
drive[0] = 0;
if(dir)
dir[0] = 0;
if(fname)
fname[0] = 0;
if(ext)
ext[0] = 0;
if((length = strlen(template)) == 0)
return(0);
offset = 0;
/* get drive */
if(length >= 2)
if(template[1] == ':')
{
if(drive)
{
drive[0] = template[offset++];
drive[1] = template[offset++];
drive[2] = 0;
}
else
{
offset++;
offset++;
}
}
/* get dir */
if(offset < length)
{
tmp = strrchr(template,SLASHC);
if(tmp)
{
tmp++; /* first character after slash */
len = tmp - &template[offset];
if(len >=0 && len < 80 && dir)
strncpy(dir,&template[offset],len);
if(len < 80 && dir)
dir[len] = 0;
offset += len;
}
}
else
return(0);
/* get fname */
if(offset < length)
{
tmp = strrchr(template,'.');
if(tmp < strrchr(template,SLASHC) || tmp < strrchr(template,':'))
tmp = 0; /* in this case the '.' must be a directory */
if(tmp)
{
tmp++; /* first character past "." */
len = tmp - &template[offset];
if((len > 0) && (offset+len < length) && fname)
{
strncpy(fname,&template[offset],len);
fname[len] = 0;
}
offset += len;
if((offset < length) && ext)
strcpy(ext,&template[offset]);
}
else if((offset < length) && fname)
strcpy(fname,&template[offset]);
}
return(0);
}
_splitpath(char *template,char *drive,char *dir,char *fname,char *ext)
{
return splitpath(template,drive,dir,fname,ext);
}